/*
 * An index_update() to a fingerprint will be called after the index_search() to the fingerprint.
 * However, due to the existence of rewriting algorithms,
 * there is no guarantee that the index_update() will be called immediately after the index_search().
 * Thus, we would better make them independent with each other.
 *
 * The input of index_search is nearly same as that of index_update() except the ContainerId field.
 */
#ifndef INDEX_H_
#define INDEX_H_

#include "../destor.h"

struct indexElem
{
    containerid id;
    fingerprint fp;
    int32_t DepWithDelta;
    containerid baseid;
    int32_t base_size;
    int32_t delta_size;
    int32_t type;
};

struct baseEntry
{
    fingerprint fp;
    containerid id;
};

struct baseChunk
{
    fingerprint fp;
    containerid id;
    int32_t size;
    unsigned char *data;
};

/*
 * The function is used to initialize memory structures of a fingerprint index.
 */
void init_index();
/*
 * Free memory structures and flush them into disks.
 */
void close_index();
/*
 * lookup fingerprints in a segment in index.
 */
int index_lookup(struct segment *);
void lookup_base(struct segment *);
/*
 * Insert/update fingerprints.
 */
void index_update(GHashTable *features, int64_t id);

void index_delete(fingerprint *fp, int64_t id);

containerid index_lookup_delta(fingerprint *fp);

void index_check_buffer(struct segment *s);
int index_update_buffer(struct segment *s);
void prinfChunkState(struct chunk *c);

//void index_delete(fingerprint *);

extern GHashTable *(*sampling)(GSequence *chunks, int32_t chunk_num);
extern struct segment *(*segmenting)(struct chunk *c);

extern void init_segmenting_method();
extern void init_sampling_method();
extern gboolean g_container_equal(containerid *, containerid *);
//extern void super_feature_rabin(unsigned char*, int, struct superF*);
//extern void super_feature_ae_6(struct chunk* ck);
//extern void super_feature_ae_12(struct chunk* ck);
//extern void sird_rabin_fix(unsigned char*, int, struct superF*);
//extern void sird_rabin_cd_mod(unsigned char*, int, struct superF*);
//extern void sird_rabin_cd_min(unsigned char*, int, struct superF*);
//extern void super_feature_ae_more(struct chunk* ck);
extern struct chunk *get_simi_chunk(struct chunk *);

extern GHashTable *base_sparse_chunks;

gboolean g_feature_equal(char *a, char *b);
guint g_feature_hash(char *feature);

#endif
